<?php
/**
 * Dao of Customer
 *
 * @author fsqijy
 */


require_once BaseUtil::getModulePath("base") . '/models/BaseDao.php';
class CampusesDao extends BaseDao{
    protected $_name;
    public function  _setup() {
        $this->_name = $this->prefix() . "agent_campuses";
        parent::_setup();
    }
    public function getCampusByDictId($areaDictId){
        $select = $this->db_r->select();
        $select->from($this->_name);
        $select->where("is_delete = 0");
        $select->where("area_dict_id = ? ",$areaDictId);
        $select->where("visible = 1 ");
        $sql = $select->__toString();
        return $this->db_r->fetchAll($sql);
    }
    public function getCampusByName($campusName){
        $select = $this->db_r->select();
        $select->from($this->_name);
        $select->where("is_delete = 0");
        $select->where("area_name = ? ",$campusName);
        $select->where("visible = 1 ");
        $sql = $select->__toString();
        return $this->db_r->fetchRow($sql);
    }
    
/*
 * Steve
 */
    public function getCampusById($campusId,$visible){
    	$select = $this->db_r->select();
        $select->from($this->_name);
        $select->where("is_delete = 0");
        $select->where("id = ? ",$campusId);
        if($visible == 1){
            $select->where("visible = 1 ");
        }
        $sql = $select->__toString();
        return $this->db_r->fetchRow($sql);
    }
    
    public function getAllCampuses(){
    	$select = $this->db_r->select();
        $select->from($this->_name);
        $select->where("is_delete = 0");
        $select->where("visible = 1 ");
        $select->order('convert(area_name using gbk)');
        $sql = $select->__toString();
        return $this->db_r->fetchAll($sql);
    }
    
    public function updateCampus($campus,$campusId){
    	$where = $this->db_w->quoteInto('id = ?', $campusId);
        $this->updateData($campus,$where);
    }
    
    public function deleteCampus($campusId){
    	$db = $this->db_w;
        $set = array("is_delete" => 1,'modified'=> date("Y-m-d H:i:s"));
        $where = $db->quoteInto('id = ? ', $campusId);
        $this->update($set, $where);
    }
}
